<!-- 订单列表 -->
<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <el-row :gutter="20">
        <el-col :span="8">
          <el-input placeholder="请输入搜索内容" v-model="queryInfo.query" clearable @clean='getOrderList'>
            <el-button slot="append" icon="el-icon-search" @click="getQueryAboutList" ></el-button>
          </el-input>
        </el-col>
      </el-row>
      <el-table :data="orderList" border style="width: 100%" stripe index>
        <el-table-column
          type="index"
          label="#"
          width="80">
        </el-table-column>
        <el-table-column
          prop="order_number"
          label="订单编号"
          >
        </el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格">
        </el-table-column>
        <el-table-column
          prop="pay_status"
          label="是否付款">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status === '1'">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="is_send"
          label="是否发货">
        </el-table-column>
        <el-table-column
          prop="create_time"
          label="下单时间">
          <template slot-scope="scope">
            {{scope.row.create_time | dataFormat}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template  slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="查看" placement="top" :enterable='false'>
              <el-button type="danger" icon="el-icon-view" size="small" @click="btnViewClick(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="编辑" placement="top" :enterable='false'>
              <el-button type="primary" icon="el-icon-edit" size="small" @click="btnEditClick(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="定位" placement="top" :enterable='false'>
              <el-button type="success" icon="el-icon-location" size="small" @click="btnLocationClick(scope.row)"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[1,5,10,20,50]"
        :current-page="queryInfo.pagenum"
        :page-size="queryInfo.pagesize"
        :total="total">
      </el-pagination>
    </el-card>
    <!-- 编辑 -->
    <el-dialog title="修改" :visible.sync="editDialogVisible"
      width="50%"
      @close="editDialogClosed">
      <!-- dialog主题区域 -->
      <el-form :model="editForm" :rules="editFormRules"
        ref="editFormRef" label-width="100px">
        <el-form-item label="省市区/县" prop="address1" >
          <el-cascader :options="cityData" v-model="editForm.address1"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2" >
          <el-input v-model="editForm.address2" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editDialogClick">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流定位 -->
    <el-dialog
      title="物流进度"
      :visible.sync="proDialogVisible"
      width="50%"
      >
      <!-- 主要内容时间线 -->
      <el-timeline>
        <el-timeline-item
          v-for="(item, index) in logisticsInfo"
          :key="index"
          :timestamp="item.time">
          {{item.context}}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from '../../assets/citydata'
export default {
  created () {
    this.getOrderList()
  },
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orderList: [],
      total: 0,
      editDialogVisible: false,
      editForm: {
        address1: [],
        address2: ''
      },
      editFormRules: {
        address1: [
          {
            required: true,
            message: '请选择省市区县',
            trigger: 'blur'
          }
        ],
        address2: [
          {
            required: true,
            message: '请填写详细地址',
            trigger: 'blur'
          }
        ]
      },
      cityData: cityData,
      proDialogVisible: false,
      logisticsInfo: []
    }
  },
  methods: {
    async getOrderList () {
      const { data: res } = await this.$http.get(`orders`, {
        params: this.queryInfo
      })
      if (res.meta.status !== 200) {
        return this.$.message.error('获取订单失败')
      }
      this.orderList = res.data.goods
      this.total = res.data.total
      console.log(res.data)
    },
    handleSizeChange (num) {
      this.queryInfo.pagesize = num
      this.getOrderList()
    },
    handleCurrentChange (num) {
      this.queryInfo.pagenum = num
      this.getOrderList()
    },
    // 查看订单详情
    btnViewClick () {

    },
    // 修改订单地址
    btnEditClick (order) {
      this.editDialogVisible = true
    },
    editDialogClick () {
      this.$refs.editForm.validate(async (istrue, obj) => {
        if (!istrue) return
        const { data: res } = await this.$http.put(`orders/`, {
          params: this.queryInfo
        })
        if (res.meta.status !== 200) {
          return this.$.message.error('修改订单失败')
        }
        this.$message.success('修改订单成功！')
        this.editDialogVisible = false
        this.getOrderList()
      })
    },
    editDialogClosed () {
      this.$resf.editFormRef.resetFields()
    },
    async btnLocationClick (order) {
      const { data: res } = await this.$http.get(`/kuaidi/804909574412544580`)
      if (res.meta.status !== 200) {
        return this.$.message.error('获取物流信息失败')
      }
      this.logisticsInfo = res.data
      console.log(res.data)
      this.proDialogVisible = true
    },
    proDialogClick () {

    },
    getQueryAboutList () {

    }
  }
}

</script>
<style lang='less' scoped>
.el-cascader{
  width: 100%;
}
</style>
